package cn.ysym.dao;


import android.content.Context;

import java.util.ArrayList;
import java.util.List;

import cn.ysym.model.ShippingMove;

/**
 * @author zhou
 * @createTime 2021-11-05 9:45
 */
public class ShippingMoveDao extends DaoBase{
    public ShippingMoveDao(Context context) {
        super(context);
    }

    public List<ShippingMove> query(String filterStr) {
        List<ShippingMove> ret = new ArrayList<>();
        List<String[]> obis;

        if (filterStr != null && filterStr.length() > 0)
            obis = this.query(Integer.MAX_VALUE, "select moveId, toDealerName from shipping_move where moveId like '%" + filterStr + "%' or toDealerName like '%" + filterStr + "%' order by moveId");
        else
            obis = this.query(Integer.MAX_VALUE, "select moveId, toDealerName from shipping_move order by moveId");

        for (String[] row : obis) {
            ShippingMove shippingMove = new ShippingMove();
            shippingMove.setMoveId(Integer.parseInt(row[0]));
            shippingMove.setToDealerName(row[1]);
            ret.add(shippingMove);
        }
        return ret;
    }

    public void insert(ShippingMove model) {
        this.execSql("insert into shipping_move(moveId, toDealerName) values(?, ?)", model.getMoveId(), model.getToDealerName());
    }

    public void deleteByMoveId(Integer moveId) {
        this.execSql("delete from shipping_move where moveId = ?", moveId);
    }

    public void clearAll() {
        this.execSql("delete from shipping_move");
    }
}
